package com.tvb.comm.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {

	public static boolean isBlank(String origin) {
		return (origin != null ? (origin.trim().length() == 0) : true);
	}

	public static boolean isNoBlank(String origin) {
		return (origin != null ? (origin.trim().length() > 0) : false);
	}

	/**
	 * 判断是否是number类型字符串
	 * @param number
	 * @return
	 */
	public static boolean isNumber(String number) {
		if (isNoBlank(number)) {
			Pattern pattern = Pattern.compile("[0-9]+(.[0-9]{2})+");
			Matcher isNum = pattern.matcher(number.trim());
			if (!isNum.matches()) {
				return false;
			}
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * 判断是否是int
	 * @param number
	 * @return
	 */
	public static boolean isInteger(String number) {
		if (isNoBlank(number)) {
			Pattern pattern = Pattern.compile("[0-9]+");
			Matcher isNum = pattern.matcher(number.trim());
			if (!isNum.matches()) {
				return false;
			}
			return true;
		} else {
			return false;
		}
	}
}
